<?php

namespace app\api\controller;

//不需要usertoken和devicetoken的类
use think\Db;
use WebGeeker\Validation\Validation;

class Not
{

    public static function getMongoObj($name)
    {
        return Db::connect("db_mongo")->name($name);
    }

    //获取回复详情页点赞列表
    public function getFavourUserList()
    {
        try {
            Validation::validate($_GET, [
                "remark_id" => "Required|Str|StrLenGe:1",
                "page" => "Required|IntGe:1"
            ]);

            $remark_id = $_GET['remark_id'];

            $page = $_GET['page'];

            //判断当前评论存不存在
            self::getMongoObj('item_remark')->where(['id' => $remark_id])->findOrFail();

            //获取点赞的列表
            $list = self::getMongoObj('remark_favour_record')
                ->where(['remark_id' => $remark_id, 'remark_favour_status' => '1', 'user_type' => 1])
                ->field('remark_favour_head_img,remark_favour_nick_name,user_id')
                ->order('remark_favour_time')
                ->select();

            $user_obj = Db::name('user');

            foreach ($list as $key=>$value){

                $is_member_info = $user_obj->where(['user_id'=>$value['user_id']])->field('is_member,member_end_time')->find();

                if($is_member_info['is_member'] == 0){
                    $value['is_member'] = 0;
                }else{
                    if($is_member_info['member_end_time'] < time()){
                        $value['is_member'] = 1;
                    }else{
                        $value['is_member'] = 0;
                    }
                }

                unset($value['user_id']);
                unset($value['id']);

                $list[$key] = $value;

            }

            successBack($list);
        } catch (\Exception $exception) {
            errorBack($exception);
        }
    }
}